Skip to content

Read the results of an anomaly detection model ​

An anomaly detection model makes one decision per image: good (OK) or defective (NOK). Its results tell how often that decision is right, how many good products it would reject and how many defects it would let through. In this guide you read the results of a model that inspects glass jars, and open the images it got wrong.

What you will learn

  • What accuracy, false rejects and defects found measure
  • How to read the OK / NOK matrix
  • How to find the images it got wrong, and why

Before you start

You need an anomaly detection dataset with a finished training. Labeling one is explained in Mark images as normal or anomaly.

1. Open the model ​

Open the dataset, go to the «Models» tab and click the card of a finished model. The card already shows the model type, here Padim, and how many images it was trained on.

2. Choose the images they are measured on ​

The selector at the top right of the scores chooses which images they are measured on: «Test», «Validation» or «All». A model opens on «Test»; when those images include no defect, as here, the scores stay empty and a note says so. Choose «All». An anomaly model learns only from good images, so every defective image of the dataset is used to test it.

Choose the images they are measured on

3. Read the three scores ​

«Performance metrics» judges the model image by image, with three scores:

  • «Accuracy». The share of images, good and defective, that get the right label.
  • «False rejects». The share of good images the model calls NOK: on the line, good products thrown away. Lower is better, and its ring is red.
  • «Defects found». The share of defective images the model catches. The rest would reach the customer.

Here the model catches 88 % of the defective jars but rejects one of the two good jars it was tested on. A dozen good images are few to learn what a normal jar looks like.

Read the three scores

4. Read the OK / NOK matrix ​

Each row is what the image really is, OK or NOK, and each column what the model said. The diagonal holds the right answers. The top right cell is the false rejects, good jars called NOK; the bottom left one is the defects that got through. «Show units» counts images instead of percentages.

Read the OK / NOK matrix

5. Browse the evaluation images ​

Click «Evaluation images». Each image shows the label the model gave and its anomaly score; a green frame means the label is right, a red one that it is wrong. The model calls NOK the images that score from 50 % up: the higher the score, the more the image differs from the good ones it learned.

Browse the evaluation images

6. Show only the mistakes ​

Set «Prediction» to «Incorrect» to keep only the mistakes: good jars called NOK, and defective ones called OK. Look at their scores. A mistake close to 50 % is a near miss; a good jar scoring far above it shows something the model has not seen among the good images, like a reflection or another position, and more good images of that kind will teach it. «Class» narrows the list to the good or the defective images.

Show only the mistakes

7. Check how it was trained ​

Below the scores, «Model details» shows how many images went into training, validation and test, the model type, the image resolution and how long it trained. Padim makes a single pass over the good images, so it trains in seconds.

Check how it was trained

Improving an anomaly model ​

  • Too many false rejects. Add good images, as varied as the line produces them (positions, reflections, batches), and train again.
  • Defects that get through. Check that they are marked NOK, paint the defect on a few of them, and try another model of the list, such as Dinomaly.
  • «No NOK images in this subset». The chosen images include no defect, so «Defects found» cannot be measured: choose «All».
  • Which images it got wrong. Go by the matrix, and by the frames and the «Prediction» filter of «Evaluation images», rather than by the viewer that opens when you click an image or a cell of the matrix.

Next steps ​

Recorded on Rosepetal release 1.8.15.